<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2019 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author:kane < chengjin005@163.com>
// +----------------------------------------------------------------------
namespace app\portal\model;

use Think\Db;
use think\Model;

class UserModel extends Model
{
    public $page = 10;


    //分页查询
    public function get_user_info_arr($where = null, $order = null)
    {

        if (empty($order)) {
            $order = ['id' => 'desc'];
        }
        $list = Db::name('user')
            ->where($where)->order($order)
            ->paginate($this->page);
        return $list;
    }

    //条件查询
    public function user_info($where)
    {

        return $list = Db::name('user')
            ->where($where)
            ->select();
    }

    //删除
    function user_info_delete($where)
    {
        // 启动事务
        Db::startTrans();
        try {
            Db::name('user')->where($where)->delete();
            adminLog(Db::name('user')->getLastSql(), '删除用户');//增加日志记录
            // 提交事务
            Db::commit();
        } catch (\Exception $e) {
            // 回滚事务
            Db::rollback();
            return '删除失败';
        }

        return 1;
    }


    //api访问
    public function curl($url = '', $param = '')
    {
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);  //curl可以直接
        curl_setopt($curl, CURLOPT_HEADER, 1);//设置header
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且输出到屏幕上
        curl_setopt($curl,CURLOPT_HTTPHEADER,array("Content-type: application/json;charset='utf-8'")); //设置响应头

        curl_setopt($curl,CURLOPT_POST,1);//post提交方式
        $data_ = json_encode($param);
        curl_setopt($curl,CURLOPT_POSTFIELDS,$data_);

        $data = curl_exec($curl);
        curl_close($curl);

        return $data;
    }
}